//
//  XJNoAddressView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/21.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  没有收货地址view

#import "XJNoAddressView.h"
@interface XJNoAddressView()

/**底部背景view*/
@property (nonatomic, strong) UIView *noAddressBgView;
@property (nonatomic, strong) UIImageView *noAddressImageView;
@property (nonatomic, strong) UILabel *noAddressLable;
@property (nonatomic, strong) UIButton *addButton;

@end
@implementation XJNoAddressView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

#pragma mark - 一 初始化

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
        XJLog(@"");
    }
    return self;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        XJLog(@"");
    }
    return self;
}

- (void)setupView {
    [self addSubview:self.noAddressBgView];
    
    [self.noAddressBgView addSubview:self.noAddressImageView];
    [self.noAddressBgView addSubview:self.noAddressLable];
    [self.noAddressBgView addSubview:self.addButton];
}

#pragma mark - 二 lazy
- (UIView *)noAddressBgView {
    if (!_noAddressBgView) {
        _noAddressBgView = [[UIView alloc] init];
    }
    return _noAddressBgView;
}

- (UIImageView *)noAddressImageView {
    if (!_noAddressImageView) {
        _noAddressImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tip_address"]];
    }
    return _noAddressImageView;
}

- (UILabel *)noAddressLable {
    if (!_noAddressLable) {
        _noAddressLable = [[UILabel alloc] init];
        _noAddressLable.text = @"您还没有收货地址";
    }
    return _noAddressLable;
}

- (UIButton *)addButton {
    if (!_addButton) {
        _addButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_addButton setTitle:@"新增收货地址" forState:(UIControlStateNormal)];
        _addButton.layer.masksToBounds = YES;
        _addButton.layer.cornerRadius = 10;
        _addButton.backgroundColor = XJCOLOR_RGB(255, 218, 67);
        [_addButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [_addButton setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateHighlighted)];
        [_addButton addTarget:self action:@selector(addButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _addButton;
}
#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.noAddressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.noAddressImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.noAddressBgView).offset(50);
        make.centerX.equalTo(self.noAddressBgView);
        make.size.mas_equalTo(CGSizeMake(150, 150));
    }];
    
    [self.noAddressLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.noAddressImageView.mas_bottom);
        make.centerX.equalTo(self.noAddressBgView);
        make.size.mas_equalTo(CGSizeMake(150, 50));
    }];
    
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.noAddressLable.mas_bottom);
        make.centerX.equalTo(self.noAddressBgView);
        make.size.mas_equalTo(CGSizeMake(130, 40));
    }];
}

#pragma mark - 四 事件回调
- (void)addButtonAction {
    
    if (self.noAddressViewAddAddressBlock) {
        self.noAddressViewAddAddressBlock();
    }
}

- (void)xj_showNoAddressViewInView:(UIView *)view {
    [view addSubview:self];
}

- (void)xj_hideNoAddressView {
    [self removeFromSuperview];
}
@end
